<template>
  <div>
    <hy-order-descriptions :orderId='orderId' v-if='loaded'></hy-order-descriptions>
    <a-descriptions bordered size='small' :column='4' title='退货单信息' style='margin-top: 20px' v-if='orderForm.outOrderNo'>
      <a-descriptions-item label='订单编号'>
        {{ orderForm.orderNo }}
      </a-descriptions-item>
      <a-descriptions-item label='退货单号'>
        {{ orderForm.outOrderNo }}
      </a-descriptions-item>
      <a-descriptions-item label='退货日期'>
        {{ orderForm.sendDate }}
      </a-descriptions-item>

      <a-descriptions-item label='订单状态'>
        <a-tag color='#87d068' v-if='orderForm.orderState==0'>未提交</a-tag>
        <a-tag color='#87d068' v-if='orderForm.orderState==1'>{{ orderForm.taskName }}</a-tag>
        <a-tag color='#f50' v-if='orderForm.orderState==2'>已审批</a-tag>
      </a-descriptions-item>

      <a-descriptions-item label='备注' :span='2' v-if='orderForm.remark'>
        {{ orderForm.remark }}
      </a-descriptions-item>
    </a-descriptions>
    <a-divider orientation='left'>发货信息</a-divider>
    <f-table ref='parentOrder' rowKey='orderDetailsId' :showTotal='true' :tableColumns='parentOrderDetailsColumns' :scroll='{x:true}' handler='hyOrderReturnHandler' :pageSize='80' :operator='operator' :params='parentOrderParam' :api='api.hyOrderDetails' :autoLoad='false' :showPagination='false' :multiple='false'>
    </f-table>
    <a-divider orientation='left'>退货信息</a-divider>
    <f-table ref='orderDrugs' rowKey='orderDetailsId' :showTotal='true' :tableColumns='orderDetailsColumns' :scroll='{x:true}' handler='hyOrderReturnHandler' :pageSize='80' :operator='operator' :params='queryParam' :api='api.hyOrderDetails' :autoLoad='false' :showPagination='false' :multiple='false'>
    </f-table>
    <hy-order-calcuate-drawer ref='calcuateDrawer'></hy-order-calcuate-drawer>
  </div>

</template>

<script>
import api from "../../../js/api"
import ProcessImage from "../../../../flowable/process/process_image"
import HyOrderCalcuateDrawer from "../../../order/caclulate/hy_order_calculate_drawer"
import { commonMixins } from "@/core/mixins/commonMixins"
import HyOrderDescriptions from "@/views/module/haiying/order/details/hyorder_descriptions"

export default {
  name: "HyBackOrderApprove",
  components: { HyOrderDescriptions, HyOrderCalcuateDrawer, ProcessImage },
  mixins: [commonMixins],
  data() {
    let me = this
    //操作按钮
    let operator = []

    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {},
      orderId: null,
      loaded: false,
      parentOrderParam: {},
      processImageVisible: false,
      show: false,
      chaiModal: false,
      formItem: {},
      orderForm: {},
      operator: operator,
      parentOrderDetailsColumns: [],
      orderDetailsColumns: [],
      columns2: [],
      customHeaderCell: (column) => {
        return {
          style: {
            "backgroundColor": "#722ED1",
            color: "red"
          }
        }
      }
    }
  },
  created() {
  },
  computed: {
    title: function() {
      return this.saleType == "CHC" ? "退货" : "补货"
    }
  },
  methods: {
    getOrderDetailsColumns(data) {
      let orderDetailsColumns = [
        {
          title: "序号",
          width: "60px",
          align: "center",
          dataIndex: "rowIndex",
          customRender: function(text, record, index) {
            return (record.rowIndex !== "合计") ? (parseInt(index) + 1) : record.rowIndex
          }
        }, {
          title: "商品名称",
          align: "center",
          width: "180px",
          ellipsis: true,
          dataIndex: "drugsName"
        }, {
          title: "批号",
          align: "center",
          width: "90px",
          dataIndex: "drugLotNo"
        }, {
          title: "规格",
          align: "center",
          ellipsis: true,
          width: "140px",
          dataIndex: "drugsSpec"
        }, {
          title: "销售单价",
          align: "center",
          width: "80px",
          dataIndex: "salePrice"
        }, , {
          title: "退货数量",
          align: "center",
          width: "80px",
          needTotal: true,
          dataIndex: "saleNum"
        }, {
          title: "退货金额",
          align: "center",
          needTotal: true,
          width: "90px",
          dataIndex: "saleAmount"
        }, {
          title: "退货原因",
          align: "center",
          width: "90px",
          dataIndex: "reason"
        }
      ]
      return orderDetailsColumns
    },
    getParentOrderDetailsColumns(data) {
      let parentOrderDetailsColumns = [
        {
          title: "序号",
          width: "60px",
          align: "center",
          dataIndex: "rowIndex",
          customRender: function(text, record, index) {
            return (record.rowIndex !== "合计") ? (parseInt(index) + 1) : record.rowIndex
          }
        }, {
          title: "商品名称",
          align: "center",
          width: "180px",
          ellipsis: true,
          dataIndex: "drugsName"
        }, {
          title: "批号",
          align: "center",
          width: "90px",
          dataIndex: "drugLotNo"
        }, {
          title: "规格",
          align: "center",
          ellipsis: true,
          width: "140px",
          dataIndex: "drugsSpec"
        }, {
          title: "销售单价",
          align: "center",
          width: "80px",
          dataIndex: "salePrice"
        }, , {
          title: "销售数量",
          align: "center",
          width: "80px",
          needTotal: true,
          dataIndex: "saleNum"
        }, {
          title: "销售金额",
          align: "center",
          needTotal: true,
          width: "90px",
          dataIndex: "saleAmount"
        }
      ]
      return parentOrderDetailsColumns
    },
    setData(data) {
      if (data && data.orderId) {
        let params = {
          orderId: data.orderId,
          handlerName: "hyOrderGetHandler"
        }
        this.http.get(this, {
          url: this.api.hyorder.get,
          params: params,
          success: (me, data) => {
            this.orderForm = data
            this.orderId=data.parentId
            this.loaded = true
          }
        })
        this.queryParam.orderId = data.orderId
        this.orderDetailsColumns = this.getOrderDetailsColumns(data)
        this.parentOrderDetailsColumns = this.getParentOrderDetailsColumns(data)
        this.$refs["orderDrugs"].refresh(false)
        this.parentOrderParam.orderId = data.parentId
        this.$refs["parentOrder"].refresh(false)
      }
    },
    renderTdBackground(record, flag) {
      if (record.costPrice > record.salePrice) {
        return {
          style: {
            "background-color": "rgb(255,150,150)"
          }
        }
      }
    },
    processImg(order) {
      this.processInstanceId = order.processInstanceId
      this.processImageVisible = true
    }
  }
}
</script>
<style lang='less'>


</style>